package com.visionet.waveletData.web.service.plan;

import com.visionet.waveletData.web.entity.group.Group;
import com.visionet.waveletData.web.entity.plan.PlayGroup;
import com.visionet.waveletData.web.entity.plan.PlayPlan;
import com.visionet.waveletData.web.repository.group.GroupDao;
import com.visionet.waveletData.web.repository.plan.PlanGroupDao;
import com.visionet.waveletData.web.repository.plan.PlayPlanDao;
import com.visionet.waveletData.web.service.BaseService;
import com.visionet.waveletData.web.vo.plan.PlanGroupVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class PlanGroupService extends BaseService{
	
	@Resource
	private PlanGroupDao planGroupDao;
	
	@Resource
	private PlayPlanDao playPlanDao;
	@Resource
	private GroupDao groupDao;

	@Autowired
	private PlayPlanService playPlanService;

	
	public List<PlanGroupVo> findPlanGroupByPlanId(String planId){
		return planGroupDao.findPlanGroupVoByPlanId(planId);
	}
	
	public void deletePlanGroup(Long id){
		PlayGroup playGroup = planGroupDao.findOne(id);
		Group g = groupDao.findOne(Long.valueOf(playGroup.getGroupId()));
		g.setInPlanId(null);
		groupDao.save(g);
		playGroup.setIs_deleted("1");
		planGroupDao.save(playGroup);
		PlayPlan playPlan = playPlanDao.findOne(Long.valueOf(playGroup.getPlanId()));
		playPlan.setUpdateDate(new Date()); 
		playPlanDao.save(playPlan);
		if(playPlan != null){
			playPlanService.curdPlanData(playPlan.getId());
		}
	}
	public void savePlanGroup(PlayGroup playGroup){
		planGroupDao.save(playGroup);
	}
	public List<PlayGroup> findPlanGroupByPlanIdAndGroupId(String planId,String groupId){
		return planGroupDao.findPlanGroupByPlanIdAndGroupId(planId, groupId);
	}
}
